
#include "GamePet.h"
#include "CreatureManager.h"
#include "ExpConfig.h"

GamePet::GamePet()
{
	mType = GCTPET;
}


GamePet::~GamePet()
{

}

fint32			GamePet::GetExp()
{
	return 0;
}

fvoid			GamePet::SetName( const fbyte* name )
{
	STRCPY( mData.Name , name ) ;
}

fvoid			GamePet::Init( GameEnemy* enemy )
{
	mEnemy = enemy;
	mEnemyBase = gCreatureManager->GetEnemyBase( enemy->intValue[ GEIV_BASEID ] );
	
	
}

fvoid			GamePet::Release()
{
	GameCreature::Release();

	mEnemyBase = F_NULL;
	mEnemy = F_NULL;

	
}

fvoid			GamePet::CheckLevelUp()
{
	mData.EXP += mTempExp;
	
	while ( mData.EXP >= gExpConfig->EXP[ mData.Level + 1 ] )
	{
		mData.EXP -= gExpConfig->EXP[ mData.Level + 1 ];
		mData.Level++;
		
		fint32 temp[ 4 ];
		MEMCPY( temp , mEnemyBase->intValue + GEBIV_BASEVITALITY , 4 * sizeof( int ) );

		fint32 max = temp[0] + temp[1] + temp[2] + temp[3];
		mPetData.Vitality += mPetData.LevelUpPoint * temp[0] / max;
		mPetData.Strength += mPetData.LevelUpPoint * temp[1] / max;
		mPetData.Toughness += mPetData.LevelUpPoint * temp[2] / max;
		mPetData.Dexterity += mPetData.LevelUpPoint * temp[3] / max;
		
		mData.Vitality = (fint16)mPetData.Vitality;
		mData.Strength = (fint16)mPetData.Strength;
		mData.Toughness = (fint16)mPetData.Toughness;
		mData.Dexterity = (fint16)mPetData.Dexterity;

		mData.Base.Attack = mData.Strength;
		mData.Base.Defence = mData.Toughness;
		mData.Base.Quick = mData.Dexterity;
	}
	
	mData.NEXTEXP = gExpConfig->EXP[ mData.Level + 1 ];

	mData.Base.MAXHP = GETMAXHP( mData.Vitality , mData.Strength , mData.Toughness , mData.Dexterity );

	UpdateFightData();
}
